package threadTest.myCompletableFuture;

import java.util.concurrent.*;

/**
 * 功能描述:可完成未来组合结果
 * 2024/08/20
 *
 * @author ZhangYi
 */
public class CompletableFutureCombinedResult {

	public static void main(String[] args) throws ExecutionException, InterruptedException {
		ThreadPoolExecutor executor = new ThreadPoolExecutor(2,
				Runtime.getRuntime().availableProcessors(),
				2, TimeUnit.NANOSECONDS,
				new ArrayBlockingQueue<>(10),
				new ThreadPoolExecutor.CallerRunsPolicy());

		CompletableFuture<String> userCompletableFuture = CompletableFuture.supplyAsync(() -> {
			return new UserService().getUserInfo();
		});

		CompletableFuture<String> userRoleCompletableFuture = CompletableFuture.supplyAsync(() -> {
			return new UserRoleService().getUserRole("1");
		});

		CompletableFutureResultDto re = userCompletableFuture.thenCombine(userRoleCompletableFuture, (userInfo, userRoleInfo) -> {
			return new CompletableFutureResultDto(userInfo, userRoleInfo, "", "", "");
		}).get();

		System.out.println(re);
	}
}
